<?php

class pictures_model extends MY_Model {

    function __construct() {
        parent::__construct();
        $this->table = 'pictures';
    }

    function  find_by_id($ID){
        $q = "
		SELECT *
		FROM $this->table
		WHERE ID = $ID
		";

        $res = $this->db->query($q)->row_array();
        return $res;
        //SELECT * FROM orders LEFT JOIN suppliers ON orders.supplier_ID = suppliers.ID WHERE supplier_ID = 1
    }

    function list_all(){
        $q = "
        SELECT pictures.*, galleries.title as gallery_name, galleries.path as gallery_path
        FROM $this->table
        LEFT JOIN galleries
        ON pictures.gallery_id = galleries.id
        ";
        return $this->db->query($q)->result_array();
    }


    function find_by_gallery($gallery_id){
        $q = "
        SELECT pictures.*, galleries.title as gallery_name, galleries.path as gallery_path
        FROM $this->table
        LEFT JOIN galleries
        ON pictures.gallery_id = galleries.id
        WHERE gallery_id = $gallery_id
        ";
        
        return $this->db->query($q)->result_array();

    }
}

?>
